package net.bxx2004.pandalib.bukkit.language.script.scripts;

import net.bxx2004.pandalib.bukkit.hook.PVault;
import net.bxx2004.pandalib.bukkit.language.script.Script;
import net.bxx2004.pandalib.bukkit.language.script.ScriptBox;
import net.bxx2004.pandalib.bukkit.language.script.ScriptImpl;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@Script
public class Economy implements ScriptImpl {
    @Override
    public String scriptIdentifier() {
        return "economy";
    }

    @Override
    //take|add|look 100 -target:ZZZiChuan
    public Object scriptRealize(CommandSender performer, ScriptBox box) {
        String[] args = box.args(performer);
        switch (args[0].toLowerCase()){
            case "take" : {
                box.run(performer, runner -> {
                    PVault.removeEconomy((OfflinePlayer) runner,Double.parseDouble(args[1]));
                });
                return true;
            }
            case "add" : {
                box.run(performer, runner -> {
                    PVault.addEconomy((OfflinePlayer) runner,Double.parseDouble(args[1]));
                });
                return true;
            }
            case "has" : {
                final boolean[] m = new boolean[1];
                box.run(performer, runner -> {
                    m[0] = PVault.hasEconomy((OfflinePlayer) runner,Double.parseDouble(args[1]));
                });
                return m[0];
            }
            case "look" : {
                final double[] m = new double[1];
                box.run(performer, runner -> {
                    m[0] = PVault.checkEconomy((OfflinePlayer) runner);
                });
                return m[0];
            }
        }
        return null;
    }
}
